package com.yuqian.JavaSe.niuke;

public class Zipper {
	   public static String zipString(String iniString) {
	        // write code here
		   if(iniString==null||iniString.isEmpty()){
			   return iniString;
		   }
		   char[] a = iniString.toCharArray();
		   char[] b = new char[a.length*2];
		   int j = 0;//重复字符长度
		   int k = 0;//重复字符位置
		   //char c =a[0];//计算重复字符串的字符
		   b[k]=a[0];
		   for(int i=0;i<a.length;i++){
			   if(k>a.length){
				   return iniString;
			   }
			   if(a[i]==b[k]){
				   j++;
			   }else{
				   char[]c =String.valueOf(j).toCharArray();
				   for(int n=0;n<c.length;n++){
					   b[++k]=String.valueOf(j).charAt(n);
				   }
				   b[++k]=a[i];
				   j=1;
			   }
			   if(i==a.length-1){
				   char[]c =String.valueOf(j).toCharArray();
				   for(int n=0;n<c.length;n++){
					   b[++k]=String.valueOf(j).charAt(n);
				   }
			   }
		   }
		   return new String(b).substring(0,k+1);
	    }
	   
	   public static void main(String[] args) {
		System.out.println(Zipper.zipString("jjjjjjxxxxxxxooZLLLLLLLLQQQQQQQQQLLLLLLLLECXXXXXXXIIIIIIIIIhjjyyySSooooooooommmuuEEEEEEEEEnnnnnnnffffffAAAAAllllllllbbbbkkkkkkkkkkkkKKKKKKhhhhhhhhhooooooooooYCCCCCCOOOOOOOOOMMMMMMMMMMiiiiiivvvvvvvWWWWkkkkkkwwwwwwwMmmmmmmmmLLLwwwwwwwkkkjjjjjjttttQQQQQQQQQaaaaaaaFFFFFFFlllllllllggggggggggPPPPPPuuuuuuuuaYYYYYYwQQQFFFFFFFFFFaaaaapXXXXXXXxxxxxxQQQQQQQQQsssssGGGGfffffffddddddpppQQQQQQHHHTTTaaaaaaGGGGGGddyyyyyMhhllllllllllNNNNNNNNUUUWWWWWWLLLLLLLLLYYYYYYYYYYTTKKKKKKKKiiiiiiitttttttXXXXXXXXXLLLHZZZZZZZssssjjJJJEEEEEOOOOOttttttttttBBttttttTTTTTTTTTTrrrrttttRRRRRyyooooooaaaaaaaaarrrrrrrPPPPPPPjjPPPPddddddddddHHHHnnnnnnnnnnSSSSSSSSSSzzHHHHHHHHHddddddDDDzzzhhhhhfffffffffftttttteeeeeeeeEEEEEEEEEaaaaaaccccccccccFFFFFFFF"));
		//System.out.println(Zipper.zipString("welcometonowcoderrrrr"));
	}
}
